package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.JigouList;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.task.CallbackSky;
import artid.com.arttogo.utils.GlideUtil;
import artid.com.arttogo.utils.NetUtils;

public class AucOrgListAdapter extends BaseAdapter {
    private Context mContext;
    LayoutInflater mInflater;
    ViewHolder holder;
    CallbackSky cs;
    public List<JigouList> list;
    String width;

    public AucOrgListAdapter(Context mContext) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);

        Map<String, String> map = NetUtils
                .getDisplayMetrics((Activity) mContext);
        width = String.valueOf(Integer.valueOf(map.get(NetUtils.DM_WIDTH)) / 2);
        list = new ArrayList<JigouList>();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public void setData(List<JigouList> listin) {
        list = listin;
        notifyDataSetChanged();
    }

    public void addData(List<JigouList> listin) {
        list.addAll(listin);
        notifyDataSetChanged();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_auc_org_list, null);
            vh.iv = (ImageView) convertView
                    .findViewById(R.id.auc_org_iv);
            vh.name = (TextView) convertView
                    .findViewById(R.id.auc_org_name);
            vh.lotnum = (TextView) convertView.findViewById(R.id.auc_org_lot_num);
            vh.specnum = (TextView) convertView.findViewById(R.id.auc_org_spec_num);
            vh.recAndLotNum = (TextView) convertView.findViewById(R.id.auc_org_rec_lot_num);
            vh.site = (TextView) convertView.findViewById(R.id.auc_org_site);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        JigouList item = list.get(position);
        GlideUtil.setImage1(mContext, item.getLogo() + AppUtil.picWidthUrl, R.drawable.ic_menu_rotate, R.drawable.ic_menu_rotate, vh.iv);
//		Glide.with(mContext).load(item.getLogo()+ AppUtil.picWidthUrl)
//		.placeholder(R.drawable.ic_menu_rotate)
//		.error(R.drawable.ic_menu_rotate).into(vh.iv);
        vh.name.setText(item.getSeller_name());
        vh.lotnum.setText("拍卖会" + item.getAuction_num() + "场");
        vh.recAndLotNum.setText(item.getLotrecord_num() + "件备案" + "/" + item.getLot_num() + "件拍品");
        vh.site.setText(item.getAddress());
        vh.specnum.setText("专场" + item.getSpecial_num() + "个");

        return convertView;
    }

    class ViewHolder {
        TextView name, lotnum, specnum, recAndLotNum, site;
        ImageView iv;
    }
}
